//
//  DisplayModeView.m
//  XRmenu
//
//  Created by shengchao yang on 11-11-25.
//  Copyright 2011年 foxhis. All rights reserved.
//

#import "DisplayModeView.h"
#import "RestaurantInformationAndADView.h"

#import "NinePicsModeView.h"
#import "FivePicsModeView.h"
#import "OnePicModeView.h"

#define kTagOfStartModeView 5000
#define kTagOfStartModeViewRemove 5100

@interface DisplayModeView(Private) 
//更新显示模式界面里的选中状态
-(void) UpdateDisplayModeViewData;
@end

@implementation DisplayModeView
@synthesize delegate;

-(id) initWithStyle:(NSString *)stylename ViewName:(NSString *)vname{
    self = [super initWithStyle:stylename DishSubViewName:vname];
    if (self) {
        [self setClipsToBounds:YES];//规定所有子view里的动画必须在当前view里进行
        addNObserver(@selector(UpdateDisplayModeViewData), kMessage_DishplayModeView_UpdateData);
    }    
    return self;
}

#pragma mark -
#pragma mark 显示模式界面事件处理方法
-(void) ViewAnimationStoped{
    APPSESSION.isAnimating=NO;//标志动画结束
}
//处理切换显示模式的通知事件
-(void)changeModeView:(NSInteger)num{
    APPSESSION.isAnimating=YES;//标志动画开始
    
    //动画切换显示模式
    if ([self viewWithTag:kTagOfStartModeView]) {    
        [[self viewWithTag:kTagOfStartModeView] removeFromSuperview];
    }
    
    if(num==2){
        FivePicsModeView *fpmv=[[FivePicsModeView alloc] initWithStyle:APPSESSION.uistyle DishSubViewName:@"Main View/Display Mode View/FivePics Mode View"];
        fpmv.tag=kTagOfStartModeView;
        [self addSubview:fpmv];
        self.delegate=fpmv;
        [fpmv release];
    }
    else if(num==1){
        OnePicModeView *opmv=[[OnePicModeView alloc] initWithStyle:APPSESSION.uistyle DishSubViewName:@"Main View/Display Mode View/OnePic Mode View"];
        opmv.tag=kTagOfStartModeView;
        [self addSubview:opmv];
        self.delegate=opmv;
        [opmv release];
    }
    else if(num==0){
        NinePicsModeView *npmv=[[NinePicsModeView alloc] initWithStyle:APPSESSION.uistyle DishSubViewName:@"Main View/Display Mode View/NinePics Mode View"];
        npmv.tag=kTagOfStartModeView;
        [self addSubview:npmv];
        self.delegate=npmv;
        [npmv release];
    }
    postN(kMessage_DishplayModeView_UpdateData);
    
    //定义动画
    [UIView beginAnimations:@"flipping view" context:nil];
    [UIView setAnimationDuration:0.5f];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseIn];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView: self cache: YES];
    //下面两句要联合使用
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(ViewAnimationStoped)];
    [UIView commitAnimations];//这句是执行
}

//修改三种显示模式里的数据(通过消息调用)
-(void) UpdateDisplayModeViewData{
    [delegate UpdateModeViewDataWithPluPlu];
}

#pragma mark -
#pragma mark dealloc
-(void) dealloc{
    DebugLog(@"DishCatalogView dealloc!!!");
    delegate=nil;
    removeNObserver(kMessage_DishplayModeView_UpdateData);
    [super dealloc];
}
@end